package rpc.spring.boot.provider.starter;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import rpc.provider.spring.RpcSpringServer;
import rpc.spring.boot.provider.config.SpringBootProviderConfig;

@Configuration
public class SpringBootProviderAutoConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "rpc.provider")
    public SpringBootProviderConfig springBootProviderConfig(){
        return new SpringBootProviderConfig();
    }

    @Bean
    public RpcSpringServer rpcSpringServer(final SpringBootProviderConfig springBootProviderConfig){
        return new RpcSpringServer(
                springBootProviderConfig.getServerAddress(),
                springBootProviderConfig.getServerRegistryAddress(),
                springBootProviderConfig.getRegistryAddress(),
                springBootProviderConfig.getRegistryType(),
                springBootProviderConfig.getRegistryLoadBalanceType(),
                springBootProviderConfig.getReflectType(),
                springBootProviderConfig.getHeartbeatInterval(),
                springBootProviderConfig.getScanNotActiveChannelInterval(),
                springBootProviderConfig.getEnableResultCache(),
                springBootProviderConfig.getResultCacheExpire(),
                springBootProviderConfig.getCorePoolSize(),
                springBootProviderConfig.getMaximumPoolSize(),
                springBootProviderConfig.getFlowType(),
                springBootProviderConfig.getMaxConnections(),
                springBootProviderConfig.getDisuseStrategyType(),
                springBootProviderConfig.getEnableRateLimiter(),
                springBootProviderConfig.getRateLimiterType(),
                springBootProviderConfig.getPermits(),
                springBootProviderConfig.getMilliSeconds(),
                springBootProviderConfig.getRateLimiterFailStrategy(),
                springBootProviderConfig.getEnableFusing(),
                springBootProviderConfig.getFusingType(),
                springBootProviderConfig.getTotalFailure(),
                springBootProviderConfig.getFusingMilliSeconds(),
                springBootProviderConfig.getExceptionPostProcessorType());


    }

}
